<?php
class Log_Comments_Notes extends Controller
{
	var $table_name;
	var $column_name;
	var $note;
		
	function log_comments_notes ()
	{
		parent::Controller();
		//Check login
		$this->load->module('login');

		// load library
		//$this->load->library('table');

		// load Helpers
		$this->load->helper( array ('date', 'text'));
		
		$l = new Login();
		if ($l->_is_logged_in())
		{

		}
		else
		{
			redirect('login');
		}
	}
	
	function update_log ($table_name, $column_name, $row_id, $note)
	{
		$data = array (
						'table_name' => $table_name,
						'column_name' => $column_name,
						'row_id' => $row_id,
						'note' => addslashes($note),
						'created_by' => $this->session->userdata("user")
					);
		
		$qid = $this->db->insert ('notes_log', $data);			
	}
	
	function get_log ($table_name, $column_name, $row_id, $format = 'off')
	{
		$qry = 'SElECT 		* 
				FROM 		notes_log 
				WHERE 		table_name = "'.$table_name.'" 
						AND column_name = "'.$column_name.'" 
						AND row_id = '.$row_id.'
						AND	note <> \'\'
				ORDER BY 	created DESC';

		
		$qid = $this->db->query ($qry);		
		
		if ($qid->num_rows > 0)
		{
			if($format == 'br'){
				foreach ($qid->result_array() as $res) 
				{
					//$log[] = $res['created'].' - '.$res['created_by'].'   '. stripslashes($res['note']);
					$log[] = stripslashes($res['note']);
				}
				
				$final_log = (implode(chr(13).'<br />', $log));
				return $final_log; 					
			}elseif($format == 'hr'){
				foreach ($qid->result_array() as $res) 
				{
					//$log[] = $res['created'].' - '.$res['created_by'].'   '. stripslashes($res['note']);
					$log[] = stripslashes($res['note']);
				}
				
				$final_log = (implode(chr(13).'<hr />', $log));
				return $final_log; 					
			}else if ($format != 'off')
			{
				foreach ($qid->result_array() as $res) 
				{
					//$log[] = $res['created'].' - '.$res['created_by'].'   '. stripslashes($res['note']);
					$log[] = stripslashes($res['note']);
				}
				
				$final_log = (implode(chr(13).'', $log));
				return $final_log; 					
			}
			else
			{
				return $qid->result_array();
			}
		}
		else
		{
			return false;
		}
	}
}
?>